package org.mat.ipaas.ucenter.bff.admin.modules.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.api.system.SysPositionRestAPI;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysPositionDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 职务表
 */
@Slf4j
@Api(tags = "职务表")
@RestController
@RequestMapping("/sys/position")
public class SysPositionController {

    @Autowired
    private SysPositionRestAPI sysPositionRestAPI;

    /**
     * 分页列表查询
     *
     * @param sysPositionDTO
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "职务表-分页列表查询", notes = "职务表-分页列表查询")
    @GetMapping(value = "/list")
    public MatApiResponse<Page<SysPositionDTO>> queryPageList(SysPositionDTO sysPositionDTO,
                                                               @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        MatApiResponse<Page<SysPositionDTO>> matApiResponse = sysPositionRestAPI.queryPageList(sysPositionDTO, pageNo, pageSize);
        return matApiResponse;
    }

    /**
     * 添加
     *
     * @param sysPositionDTO
     * @return
     */
    @ApiOperation(value = "职务表-添加", notes = "职务表-添加")
    @PostMapping(value = "/add")
    public MatApiResponse<SysPositionDTO> add(@RequestBody SysPositionDTO sysPositionDTO) {
        MatApiResponse<SysPositionDTO> matApiResponse = sysPositionRestAPI.add(sysPositionDTO);
        return matApiResponse;
    }

    /**
     * 编辑
     *
     * @param sysPositionDTO
     * @return
     */
    @ApiOperation(value = "职务表-编辑", notes = "职务表-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public MatApiResponse<SysPositionDTO> edit(@RequestBody SysPositionDTO sysPositionDTO) {
        MatApiResponse<SysPositionDTO> matApiResponse = sysPositionRestAPI.edit(sysPositionDTO);
        return matApiResponse;
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "职务表-通过id删除", notes = "职务表-通过id删除")
    @DeleteMapping(value = "/delete")
    public MatApiResponse<?> delete(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse<?> matApiResponse = sysPositionRestAPI.delete(id);
        return matApiResponse;
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "职务表-批量删除", notes = "职务表-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public MatApiResponse<SysPositionDTO> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        MatApiResponse<SysPositionDTO> matApiResponse = sysPositionRestAPI.deleteBatch(ids);
        return matApiResponse;
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "职务表-通过id查询", notes = "职务表-通过id查询")
    @GetMapping(value = "/queryById")
    public MatApiResponse<SysPositionDTO> queryById(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse<SysPositionDTO> matApiResponse = sysPositionRestAPI.queryById(id);
        return matApiResponse;
    }

    /**
     * 导出excel
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls() {
        ModelAndView modelAndView = sysPositionRestAPI.exportXls();
        return modelAndView;
    }

    /**
     * 通过excel导入数据
     *
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public MatApiResponse<?> importExcel() throws IOException {
        MatApiResponse<?> matApiResponse = sysPositionRestAPI.importExcel();
        return matApiResponse;
    }

    /**
     * 通过code查询
     *
     * @param code
     * @return
     */
    @ApiOperation(value = "职务表-通过code查询", notes = "职务表-通过code查询")
    @GetMapping(value = "/queryByCode")
    public MatApiResponse<SysPositionDTO> queryByCode(@RequestParam(name = "code", required = true) String code) {
        MatApiResponse<SysPositionDTO> matApiResponse = sysPositionRestAPI.queryByCode(code);
        return matApiResponse;
    }
}
